package com.jwt.demo.util;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * 返回类
 * @param  <T>
 */
public class JsonResult<T> {

    /**
     * 状态
     *
     */
    private String code;
    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 数据内容
     */
    private T data;

    /**
     * token
     * @author: 陈先生
     * @date 2021/4/30 10:07
     */
    private String token;

    /**
     * 异常错误信息,空值时，不输出该字段
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String devTack;

    /**
     * 无参数构造方法
     * <p>默认:code="000000"</p>
     */
    public JsonResult() {
        this.code = "200";
    }

    /**
     * 创建一个成功的结果集
     *
     * @param data 数据内容
     */
    public JsonResult(T data) {
        this.code = "000000";
        this.data = data;
    }

    public JsonResult(String code, String errorMessage, T data) {
        this.code = code;
        this.errorMessage = errorMessage;
        this.data = data;
    }

    public JsonResult(String code, String errorMessage) {
        this.code = code;
        this.errorMessage = errorMessage;
    }

    public JsonResult(String code, String errorMessage, T data, String token) {
        this.code = code;
        this.errorMessage = errorMessage;
        this.data = data;
        this.token = token;
    }

    /**
     * 验证结果是否成功
     *
     * @return Boolean
     */
    public boolean verifySuccess() {
        return "000000".equals(this.code);
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getDevTack() {
        return devTack;
    }

    public void setDevTack(String devTack) {
        this.devTack = devTack;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }
}
